//
//  NotificationManger.swift
//  MyTest
//
//  Created by guanzhongwang on 2021/5/11.
//

import Foundation
struct NotificationMananger{

    static func addNotification(_ name:NoticeName,target:Any,selector:Selector,object:Any?=nil){
        NotificationCenter.default.addObserver(target, selector: selector, name: NotificationName.Name(name), object: object)
    }
    static func removeNotification(_ name:NoticeName,target:Any,object:Any?=nil) {
        NotificationCenter.default.removeObserver(target, name: NotificationName.Name(name), object: object)
    }
    static func removeAllNotifocation(_ target:Any) {
        NotificationCenter.default.removeObserver(target)
    }
    
    static func post(_ name:NoticeName,object:Any?=nil,userInfo:[AnyHashable : Any]?=nil){
        NotificationCenter.default.post(name: NotificationName.Name(name)!, object: object,userInfo: userInfo)
    }
    
    private init(){
        
    }
    
}
enum NoticeName {
    case None
    case Custom(name:String)
    case LoginCompletion
    case NetWorkState
}

struct NotificationName {
    static func Name(_ name:NoticeName) -> Notification.Name? {
        switch name {
        case .LoginCompletion:
            return NSNotification.Name(rawValue: "LoginCompletion")
        case .Custom(name: let name):
            return NSNotification.Name(rawValue: name)
        case .NetWorkState:
            return NSNotification.Name(rawValue: "NetWorkState")
        default:
            return nil
        }
    }
    private init(){}
}

